package main

import (
	"fmt"
	"zinx/ziface"
	"zinx/znet"
)

// ping test
type PingRouter struct {
	znet.BaseRouter
}

func (pr *PingRouter)PreHandle(request ziface.IRequest) {
	fmt.Sprintf("PreHandle()..\n")
	if _,err := request.GetConnection().GetTCPConnection().Write([]byte("before ping...\n")); err != nil {
		fmt.Printf("callback before ping  error\n")
	}
}

func (pr *PingRouter)Handle(request ziface.IRequest) {
	fmt.Sprintf("Handle()..\n")
	if _,err := request.GetConnection().GetTCPConnection().Write([]byte(" ping...\n")); err != nil {
		fmt.Printf("callback ping  error\n")
	}
}

func (pr *PingRouter)PostHandle(request ziface.IRequest) {
	fmt.Sprintf("PostHandle()..\n")
	if _,err := request.GetConnection().GetTCPConnection().Write([]byte("after ping...\n")); err != nil {
		fmt.Printf("callback after ping  error\n")
	}
}

func main() {
	s := znet.NewServer("[zinx V0.3]")

	s.AddRouter(&PingRouter{})

	s.Serve()
}
